package com.caogen.cg_wl_kt.adapter

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.caogen.cg_wl_kt.R
import com.caogen.cg_wl_kt.ui.notifications.NotificFourFragment
import com.caogen.cg_wl_kt.ui.notifications.NotificOneFragment
import com.caogen.cg_wl_kt.ui.notifications.NotificThreeFragment
import com.caogen.cg_wl_kt.ui.notifications.NotificTwoFragment
import com.caogen.cg_wl_kt.utils.YDLog

/**
 * 项目名称: cg_wl_kt
 * Packages:com.caogen.cg_wl_kt.adapter
 * author: FSW
 * 创建日期: 2024/2/29 16:17
 * Describe:
 *
 */
class NotificSectionsPagerAdapter(private val context: Context, fm: FragmentManager)
    : FragmentPagerAdapter(fm) {
    //顶部tablayout的字符
    private val TAB_TITLES = arrayOf(
        R.string.tab_text_1,
        R.string.tab_text_2,
        R.string.tab_text_3,
        R.string.tab_text_4

    )
    override fun getItem(position: Int): Fragment {
        // 顶部有多少个tab，就会运行多少次（初次会加载第一第二，第三第四要点第三个tab才会运行）
        /*******新建Fragment******/
        YDLog.logd("运行第几次："+(position+1))
        when (position) {
            0 -> {
                return NotificOneFragment.newInstance(position + 1)
            }
            1 -> {
                return NotificTwoFragment.newInstance(position + 1)
            }
            2 -> {
                return NotificThreeFragment.newInstance(0)
            }
            3 -> {
                return NotificFourFragment.newInstance(0)
            }
        }
        return NotificOneFragment.newInstance(position + 1)

    }

    override fun getPageTitle(position: Int): CharSequence? {
        return context.resources.getString(TAB_TITLES[position])
    }

    override fun getCount(): Int {
        // 顶部显示多少个页，不要超过TAB_TITLES的总数.
        return 4
    }
}
